<?

require_once('QuickData.php');

$DefsPath = $GLOBALS['QD']['DefinitionsPath'];
$TableID = $_REQUEST['TableID'];
$TableDef = $_REQUEST['TableDef'];
$ObjectName = $_REQUEST['ObjectName'];
$Action = $_REQUEST['Action'];
if ($GLOBALS['QD']['UseSessions'] == TRUE)
{
	session_set_cookie_params((mktime(0, 0, 0, date("m"), date("d") + 1, date("Y")) - time()), '/', '.newfields.com');
	session_start();
	//session_destroy();
	if(isset($_SESSION['Forms'][$FormID]))
	{ // if we have the object in a session, just get a handle to it and restore the database
		$DataTable = &$_SESSION['Tables'][$TableID];
	}
	else
	{
		$DataTable = new DataForm($DefsPath . $TableDef, $TableID, $ObjectName);
		//echo "new DataTable $TableID";
		$_SESSION['Tables'][$TableID] = &$DataTable;
	}
}
else
{
	$DataTable = new DataTable($DefsPath . $TableDef, $TableID, $ObjectName);
}
if (!is_null($DataTable->Requires))
{
	if (file_exists($DefsPath . $DataTable->Requires))
	{
		include($DefsPath .  $DataTable->Requires);
	}
	else
	{
		$msg =  "{$DefsPath}.{$DataTable->Requires} - not found";
	}
}
header('Cache-Control: private');
header('Vary: Cookie');
header('Content-type: text/html');  // output as HTML

//echo $msg;
$DataTable->HandleEvents($_REQUEST);
switch($Action)
{
	case "getRecordCount";
		echo $DataTable->RecordCount();
		break;
	case "getDataTableHTML":
		echo $DataTable->getDataTableHTML();
		//echo $DataTable->GetQuery();
		break;
	case "getDataRowsHTML":
		echo $DataTable->getDataRowsHTML();
		//echo $DataTable->GetQuery();
		break;
	case "getSearchControlHTML":
		echo $DataTable->getSearchControlHTML();
		break;
	default:
}
/*
?>
<pre>
$_REQUEST:
<? print_r($_REQUEST); ?>

$DataTable->GetQuery():
<? echo $DataTable->GetQuery(); ?>
</pre>
<?
*/
?>